package com.dh.exception;

import java.util.Scanner;

public class ExceptionDem06 {
    public static void main(String[] args) {

        try {
            doSomeThing();
        } catch (MyException e) {
            System.out.println(e.getMessage());
        }

    }

    public static void doSomeThing() throws MyException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个名字");
        String name = scanner.next();
        // 如果这个名字是老王，就报一个名字异常
        if (name.equals("老王")) {
            throw new MyException("名字不能是老王");// 扔出来的异常
        }
    }
}


class MyException extends Exception {
    public MyException() {
        super();// 调用父类
    }

    public MyException(String message) {
        super(message);
    }
}
